﻿using System;
using System.Text;
using System.Web.Routing;
using System.Web.UI;
using phudieuhungthinh.BL;
using phudieuhungthinh.Helpers;

namespace phudieuhungthinh.Pages
{
    public partial class ArticlePage : Page, IRoutablePage
    {
        protected RequestContext _requestContext;

        public string Url
        {
            get { return RouteValue("url").ToString(); }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected override void CreateChildControls()
        {
            var im = new ArticleImpl();
            var item = im.GetArticle(Url);

            var html = new StringBuilder();
            html.Append("<div id='article-layout'>");
            html.AppendFormat("<div id='article-title'>{0}</div>", item.Title);
            html.AppendFormat("<div id='article-content'>{0}</div>", item.ArticleContent);
            html.Append("</div>");
            containerUI.Controls.Add(new LiteralControl(html.ToString()));

            base.CreateChildControls();
        }

        protected object RouteValue(string key)
        {
            return _requestContext.RouteData.Values[key];
        }

        #region IRoutablePage Members

        public RequestContext RequestContext
        {
            set { _requestContext = value; }
        }

        #endregion
    }
}
